<?php

namespace app\api\server\entity;

use app\api\model\entity\EntityVoiceApiModel;
use app\api\ServerBase;
use app\logic\single\GoodsSingle;
use think\Request;

class EntityVoiceServer extends ServerBase
{

    /**
     * @var EntityVoiceApiModel
     */
    private $model;
    /**
     * @var array|mixed
     */
    private $param;

    function __construct(Request $request)
    {
        $this->request = $request;
        $this->param = $request->param();
        $this->model = new EntityVoiceApiModel();
    }
    function getList(){
        [$page,$limit] = $this->getPage($this->param);
        $field= 'id,title,img,price,sale,original_price';
        $this->param['status'] = 1;
        [$list,$count] = $this->model->getApiList($this->param,[],$field,$page,$limit);
        $result['data']=$list;
        $result['count']=$count;
        $this->getMessageCode('adminMessage.success.select',2);
        return $result;
    }

    function getDetail(){
        $id =  $this->request->param('id');
        $info = $this->model->details($id,'id,title,content,img,price,sale,original_price,musics');
        if(empty($info)){
            $this->getMessageCode('code_common.not_find',1);
            return false;
        }
        $musics=[];
        foreach ($info['musics'] as $key=>$val){
            $musics[$key]['goods_id'] = $val;
            $musics[$key]['type'] = 10;
        }
        $info['goods'] = GoodsSingle::getInstance()->getGoodsList($musics);
        unset($info['musics']);
        $this->getMessageCode('adminMessage.success.select',2);
        return $info;
    }
}